package com.liao.mongodb.dao.impl;

import com.liao.mongodb.dao.UserCustomDao;
import com.liao.mongodb.pojo.TbUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.ReactiveMongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

public class UserCustomImpl implements UserCustomDao {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public TbUser queryById(String id) {
        return mongoTemplate.findById(id,TbUser.class);
    }

    @Override
    public List<TbUser> queryByUsername(String username) {
        Query query = Query.query(Criteria.where("username").is(username));
        return mongoTemplate.find(query,TbUser.class,"username");
    }

}
